<?php
defined('_JEXEC') or die('Restricted access');

$jversion = new JVersion();
$j15 = ($jversion->RELEASE == '1.5');

jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams( 'com_nspro' );
if ($j15 == true) {
  $component = JComponentHelper::getComponent( 'com_nspro' );
  $params = new JParameter( $component->params );
}

$db =& JFactory::getDBO();

$ordering = ($this->olists['order'] == 'ordering');

?>
<style type="text/css">

.icon-48-fields {
  background-image: url('components/com_nspro/img/fields48.png');
}

</style>
<form id="adminForm" action="<?php echo JRoute::_( 'index.php' );?>"  method="post" name="adminForm">
<div id="editcell">
    <table class="adminlist">
    <thead>
        <tr>
            <th width="5">
              <?php echo JHTML::_( 'grid.sort', JText::_( 'ID' ), 'id', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th width="20">
                <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->fields ); ?>);" />
            </th>
            <th class="title">
              <?php echo JHTML::_( 'grid.sort', JText::_('Name'), 'name', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th>
              <?php echo JHTML::_( 'grid.sort', JText::_('Field Type'), 'fieldtype', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th>
                <?php echo JText::_('Validation Regular Expression'); ?>
            </th>
            <th width="70">
              <?php echo JHTML::_( 'grid.sort', JText::_('Required'), 'required', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th width="70">
              <?php echo JHTML::_( 'grid.sort', JText::_('Published'), 'published', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th width="100">
                <?php echo JHTML::_( 'grid.sort', JText::_('Show on Subscriber Manager'), 'show_backend', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th width="70">
              <?php echo JHTML::_( 'grid.sort', JText::_('Field Position'), 'abovepos', $this->olists['order_Dir'], $this->olists['order']); ?>
            </th>
            <th>
                <?php echo JText::_( 'Initial Value' ); ?>
            </th>
            <th width="100">
              <?php echo JHTML::_('grid.sort',   JText::_('Order'), 'ordering', $this->olists['order_Dir'], $this->olists['order'] ); ?>
              <?php echo JHTML::_('grid.order',  $this->fields ); ?>
            </th>
            <th width="20%" class="notes">
                <?php echo JText::_( 'Notes' ); ?>
            </th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="14">
                <?php
                  print $this->pagination->getListFooter();
                ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
    <?php
    $k = 0;
    for ($i=0, $n=count( $this->fields ); $i < $n; $i++)
    {
        $row = &$this->fields[$i];
        $row->checked_out = false;
        $checked    = JHTML::_('grid.checkedout', $row, $i );
        $link       = JRoute::_( 'index.php?option=com_nspro&controller=nspro&task=fedit&cid[]='. $row->id );
        $published  = JHTML::_('grid.published', $row, $i,'tick.png','publish_x.png','f');

        ?>
        <tr class="<?php echo "row$k"; ?>">
            <td>
                <?php echo $row->id; ?>
            </td>
            <td>
                <?php echo $checked; ?>
            </td>
            <td>
                <a href="<?php echo $link; ?>"><?php echo $row->name; ?></a>
            </td>
            <td align="center">
                <?php echo $this->ftypes[$row->fieldtype]; ?>
            </td>
            <td>
                <?php echo $row->regexp; ?>
            </td>
            <td align="center">
              <?php
                if ($row->required) {
                  print JText::_('Yes');
                }
                else {
                  print JText::_('No');
                }
              ?>
            </td>
            <td align="center">
              <?php print $published; ?>
            </td>
            <td align="center">
              <?php
                if ($row->show_backend) {
                  print JText::_('Yes');
                }
                else {
                  print JText::_('No');
                }
              ?>
            </td>
            <td align="center">
              <?php
                if ($row->abovepos) {
                  print JText::_('Above Form');
                }
                else {
                  print JText::_('Below Form');
                }
              ?>
            </td>
            <td>
                <?php
                  if (strlen(htmlentities($row->value)) > 100) {
                    print JString::substr(htmlentities($row->value), 0, 100) . '...';
                  }
                  else {
                    print htmlentities($row->value);
                  }
                ?>
            </td>
            <td class="order">
              <span><?php echo $this->pagination->orderUpIcon( $i, ($i > 0), 'orderup', 'Move Up', $ordering); ?></span>
              <span><?php echo $this->pagination->orderDownIcon( $i, $n, ($i < $n), 'orderdown', 'Move Down', $ordering); ?></span>
              <input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" class="inputbox" style="text-align: center" />
            </td>
            <td>
                <?php echo $row->notes; ?>
            </td>
        </tr>
        <?php
        $k = 1 - $k;
    }
    ?>
    </tbody>
    </table>

<input type="hidden" name="option" value="com_nspro" />
<input type="hidden" name="view" value="fields" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="nspro" />
<input type="hidden" name="filter_order" value="<?php echo $this->olists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->olists['order_Dir']; ?>" />
</form>
<br/>
<center><small><i>NS Pro by <a href="http://www.mavrosxristoforos.com/">Mavrosxristoforos.com</a> Copyright 2009-2011</i></small></center>
</div>
